package com.jy.datapipeline.importserver.entity.manager;

import com.jy.datapipeline.importserver.common.constants.KeyConstant;
import com.jy.datapipeline.importserver.entity.*;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author baitiaojun
 * @类名 EntityManager
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2023/9/1 18:40
 * @版本 1.0
 */
public class EntityManager {

    private static Map<String, BasicEntity> beans = new HashMap<>();

    static {
        registerEntity(KeyConstant.IMPORT_DIRECTION_KEY, new ImportDirection());
        registerEntity(KeyConstant.IMPORT_RETRY_SUBTASK_KEY, new ImportRetrySubtask());
        registerEntity(KeyConstant.IMPORT_RULE_KEY, new ImportRule());
        registerEntity(KeyConstant.IMPORT_RULE_TABLE_KEY, new ImportRuleTable());
        registerEntity(KeyConstant.IMPORT_SQLLDR_INFO_KEY, new ImportSqlldrInfo());
        registerEntity(KeyConstant.IMPORT_SUBTASK_KEY, new ImportSubtask());
        registerEntity(KeyConstant.IMPORT_TASK_KEY, new ImportTask());
        registerEntity(KeyConstant.IMPORT_TASK_LOG_KEY, new ImportTaskLog());
        registerEntity(KeyConstant.IMPORT_RULE_TABLE_COLUMNS_KEY, new ImportRuleTable.ImportColumn());
    }

    private static void registerEntity(String beanName, BasicEntity basicEntity) {
        beans.put(beanName, basicEntity);
    }

    public static void removeEntity(String beanName) {
        beans.remove(beanName);
    }

    public static BasicEntity create(String beanName) {
        BasicEntity basicEntity = beans.get(beanName);
        return basicEntity.createClone();
    }
}
